import jwt
from sqlalchemy import true,false
import time
class MyJwt:
    def __init__(self):
        self.secret='ggaghgergrgrgshjlk;lrgkljfkndlknsugisdjkgn'

    # 加密
    def jwt_encode(self,data):
        return jwt.encode(data,self.secret,algorithm='HS256')
    # 解密
    def jwt_decode(self,token):
        payload=jwt.decode(token,self.secret,algorithms='HS256')
        return payload
    # 对比
    def check(self,token):
        payload = jwt.decode(token, self.secret, algorithms='HS256')
        newtoken=jwt.decode(payload,self.secret,algorithms='HS256')
        if token==newtoken:
            # 验证过期时间
            nowtime=int(time.time())

            if nowtime-payload['data']['exp']>3600:
                return false
            return true
        return false

myjwt=MyJwt()

